package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 友人A
 */
@RestController
@RequestMapping
@Slf4j
@Api("护理计划管理")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiModelProperty(value = "查询全部护理计划")
    public ResponseResult<List<NursingPlanVo>> findNursingPlanServiceList() {
        List<NursingPlanVo> nursingPlanVoList = nursingPlanService.findNursingPlanServiceList();
        return success(nursingPlanVoList);
    }

    @GetMapping("/nursing/plan/search")
    @ApiModelProperty(value = "分页查询护理计划", notes = "传入查询条件，name,pageNum,pageSize,stasus")
    public ResponseResult<PageResponse<NursingPlanVo>> pageNursingPlanServiceList(@RequestParam(required = false) String name,
                                                                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                                                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                                                                  @RequestParam(required = false) Integer status) {
        log.info("查询条件为：name:{},pageNum:{},pageSize:{},status:{}", name, pageNum, pageSize, status);
        PageResponse<NursingPlanVo> nursingPlanVoList = nursingPlanService.pageNursingPlanServiceList(name, pageNum, pageSize, status);
        return success(nursingPlanVoList);
    }
    @PostMapping("/nursing/plan")
    @ApiModelProperty(value = "添加护理计划", notes = "传入护理计划对象")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        log.info("传入参数为{}",nursingPlanDto);
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return success();
    }
    @GetMapping("/nursing/plan/{id}")
    @ApiModelProperty(value = "根据id查询护理计划", notes = "传入id")
    public ResponseResult getNursingPlanById(@PathVariable Long id){
        log.info("查询id为{}的护理计划",id);
       NursingPlanVo nursingPlanVoList = nursingPlanService.getNursingPlanById(id);
        return success(nursingPlanVoList);
    }
    @PutMapping("/nursing/plan/{id}")
    @ApiModelProperty(value = "根据id修改护理计划", notes = "传入id和护理计划对象")
    public ResponseResult updateNursingPlan(@PathVariable Long id,@RequestBody NursingPlanDto nursingPlanDto){
        log.info("修改id为{}的护理计划",id);
        log.info("传入参数为{}",nursingPlanDto);
        nursingPlanService.updateNursingPlan(id,nursingPlanDto);
        return success();
    }
    @DeleteMapping("/nursing/plan/{id}")
    @ApiModelProperty(value = "根据id删除护理计划", notes = "传入id")
    public ResponseResult deleteById(@PathVariable Long id){
        log.info("删除id为{}的护理计划",id);
        nursingPlanService.deleteById(id);
        return success();
    }
    @PutMapping("/nursing/{id}/status/{status}")
    @ApiModelProperty(value = "根据id修改护理计划状态", notes = "传入id和状态")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        log.info("修改id为{}的护理计划状态为{}",id,status);
        nursingPlanService.updateStatus(id,status);
        return success();
    }
}
